<?php

namespace app\api\controller;

use app\common\exception\BusinessException;
use think\Exception;
use think\response\Json;

class Feedback extends Base
{
    /**
     * 意见反馈
     * @return Json
     * @throws
     */
    public function add(): Json
    {
        // 外部参数
        $params = $this->request->param();

        // 验证规则
        $rule = [
            'type' => 'require',
            'detail' => 'require',
        ];

        // 错误信息
        $errMsg = [
            'type.require' => '反馈类型不得为空',
        ];

        // 数据验证
        $valRel = $this->validate($params, $rule, $errMsg);
        if ($valRel !== true)
        {
            throw new BusinessException($valRel, 0);
        }

        // 提交数据
        app(\app\api\logic\Feedback::class)->add($params);

        // 返回
        return $this->response([], 1, '提交成功');
    }

    /**
     *  反馈列表
     * @return Json
     */
    public function getList(): Json
    {
        // 外部参数
        $param = $this->request->param();

        // 查询数据
        $list = app(\app\api\logic\Feedback::class)->getList($param);

        // 返回
        return $this->response($list, 1);
    }
}